<<<<<<< HEAD
<?php
require_once 'service/UserService.php';

if (isset($_REQUEST['action'])){
	if($_REQUEST['action'] == 'login') {
	    $email = $_REQUEST['email'];
	    $password = $_REQUEST['password'];
	    $userService = new UserService();
	    $flag = $userService->auth($email, $password);
	    if ($flag) {
	        header("location:/".APP_CONTEXT);
	    } else {
	        echo "error";
	    }		
	}
    else if($_REQUEST['action'] == 'register') {
	    $email = $_REQUEST['email'];
	    $display_name = $_REQUEST['display_name'];
	    $password = $_REQUEST['password'];
	    $userService = new UserService();
	    $reg_flag = $userService->register($email, $display_name, $password);
	    if($reg_flag) {
		    header("location:register-success.php");
	    } 
    }
} else if(isset($_GET['email'])) {
	echo "got email addr: ". $_GET['email'];
	$userService = new UserService();
	$flag = $userService->isEmailRegistered($_GET['email']);
	if($flag){
		echo "Email has been registered";
	} else {
		echo "ok, email can be used";
	}
}
?>
<div class="span5">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#login" data-toggle="tab">用户登录</a></li>
        <li><a href="#register" data-toggle="tab">用户注册</a></li>
    </ul>
    
    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade active in" id="login">
            <form class="well" method="post">
                <input type="hidden" name="action" value="login">
                <input type="text" name="email" placeholder="Email">
                <input type="password" name="password" placeholder="Password">
                <!--  
                <label class="checkbox">
                  <input type="checkbox">Remember me
                </label>
                -->
                <button type="submit" class="btn btn-primary">登录</button>
              </form>
        </div>
        <div class="tab-pane fade in" id="register">
            <form id="regform" class="form-horizontal" method="post">
                <input type="hidden" name="action" value="register"/>
                <fieldset>
                  <div class="control-group">
                    <label class="control-label" for="focusedInput">邮箱</label>
                    <div class="controls">
                      <input id="email" class="input-xlarge focused" name="email" type="text" value="">
                      <?php if(isset($reg_flag) && !$reg_flag) echo '<span class="help-inline"> 该Email已被注册</>' ?>
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label" for="focusedInput">昵称</label>
                    <div class="controls">
                      <input id="display_name" class="input-xlarge focused" name="display_name" type="text" value="">
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label" for="focusedInput">密码</label>
                    <div class="controls">
                      <input id="regpwd" class="input-xlarge focused" name="password" type="password" value="">
                    </div>
                  </div>
                  <div class="form-actions">
                    <button type="submit" class="btn btn-primary">保存</button>
                    <button type="reset" class="btn">取消</button>
                  </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">

$(function() {
	
	$('.help-inline').each(function(){
		$(this).prev().addClass('error').parent().parent().addClass('error');
	});
	
	var error = function(el, msg){
		el.addClass('error');
		if (!el.next().is('.help-inline'))
			$('<span class="help-inline" />').text(msg).insertAfter(el);
		else
			el.next().text(msg);
		el.parent().parent().addClass('error');
		return false;
	}
	
	$("#regform").submit(function() {
		$('#regform .error').removeClass('error');
		$('#regform .help-inline').remove();
		var email = $('#email').val();
		var display_name = $('#display_name').val();
		var password = $('#regpwd').val();
		///alert(password);
		if(!email) {
			return error($('#email'), '请输入您的Email');
		} else if(!display_name) {
			return error($('#display_name'), '请输入昵称');
		} else if (!password){
			return error($('#regpwd'), '请输入密码');	
		} else if (password && password.length < 6) {
			return error($('#regpwd'), '密码长度必须大于6位');
		}
		
		if (!/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(email))
			return error($('#email'), '请检查您输入的Email的格式');

		$.get("ajax-service.php?checkemail="+email, function(data) {
		    if (data == '1') {
			    return error($('#email'), '该Email已经注册过了');
		    }
		})
		//
		//return (email && display_name && regpwd) ? true : false;
		
		return true;
	});
});
=======
<?php
require_once 'service/UserService.php';

if (isset($_REQUEST['action'])){
	if($_REQUEST['action'] == 'login') {
	    $email = $_REQUEST['email'];
	    $password = $_REQUEST['password'];
	    $userService = new UserService();
	    $flag = $userService->auth($email, $password);
	    if ($flag) {
	        header("location:/".APP_CONTEXT);
	    } else {
	        echo "error";
	    }		
	}
    else if($_REQUEST['action'] == 'register') {
	    $email = $_REQUEST['email'];
	    $display_name = $_REQUEST['display_name'];
	    $password = $_REQUEST['password'];
	    $userService = new UserService();
	    $reg_flag = $userService->register($email, $display_name, $password);
	    if($reg_flag) {
		    header("location:register-success.php");
	    } 
    }
} else if(isset($_GET['email'])) {
	echo "got email addr: ". $_GET['email'];
	$userService = new UserService();
	$flag = $userService->isEmailRegistered($_GET['email']);
	if($flag){
		echo "Email has been registered";
	} else {
		echo "ok, email can be used";
	}
}
?>
<div class="span5">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#login" data-toggle="tab">用户登录</a></li>
        <li><a href="#register" data-toggle="tab">用户注册</a></li>
    </ul>
    
    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade active in" id="login">
            <form class="well" method="post">
                <input type="hidden" name="action" value="login">
                <input type="text" name="email" placeholder="Email">
                <input type="password" name="password" placeholder="Password">
                <!--  
                <label class="checkbox">
                  <input type="checkbox">Remember me
                </label>
                -->
                <button type="submit" class="btn btn-primary">登录</button>
              </form>
        </div>
        <div class="tab-pane fade in" id="register">
            <form id="regform" class="form-horizontal" method="post">
                <input type="hidden" name="action" value="register"/>
                <fieldset>
                  <div class="control-group">
                    <label class="control-label" for="focusedInput">邮箱</label>
                    <div class="controls">
                      <input id="email" class="input-xlarge focused" name="email" type="text" value="">
                      <?php if(isset($reg_flag) && !$reg_flag) echo '<span class="help-inline"> 该Email已被注册</>' ?>
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label" for="focusedInput">昵称</label>
                    <div class="controls">
                      <input id="display_name" class="input-xlarge focused" name="display_name" type="text" value="">
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label" for="focusedInput">密码</label>
                    <div class="controls">
                      <input id="regpwd" class="input-xlarge focused" name="password" type="password" value="">
                    </div>
                  </div>
                  <div class="form-actions">
                    <button type="submit" class="btn btn-primary">保存</button>
                    <button type="reset" class="btn">取消</button>
                  </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">

$(function() {
	
	$('.help-inline').each(function(){
		$(this).prev().addClass('error').parent().parent().addClass('error');
	});
	
	var error = function(el, msg){
		el.addClass('error');
		if (!el.next().is('.help-inline'))
			$('<span class="help-inline" />').text(msg).insertAfter(el);
		else
			el.next().text(msg);
		el.parent().parent().addClass('error');
		return false;
	}
	
	$("#regform").submit(function() {
		$('#regform .error').removeClass('error');
		$('#regform .help-inline').remove();
		var email = $('#email').val();
		var display_name = $('#display_name').val();
		var password = $('#regpwd').val();
		///alert(password);
		if(!email) {
			return error($('#email'), '请输入您的Email');
		} else if(!display_name) {
			return error($('#display_name'), '请输入昵称');
		} else if (!password){
			return error($('#regpwd'), '请输入密码');	
		} else if (password && password.length < 6) {
			return error($('#regpwd'), '密码长度必须大于6位');
		}
		
		if (!/^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(email))
			return error($('#email'), '请检查您输入的Email的格式');

		$.get("ajax-service.php?checkemail="+email, function(data) {
		    if (data == '1') {
			    return error($('#email'), '该Email已经注册过了');
		    }
		})
		//
		//return (email && display_name && regpwd) ? true : false;
		
		return true;
	});
});
>>>>>>> 20d6c557d209a3f376420616f57b4bd953611975
</script>